package fr.pud.client.model;

import java.io.Serializable;

import fr.pud.client.i18n.LanguagesConstants;

/**
 * The implementation of a specific query.
 * Apr 9, 2012 - OSE.
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         Query.java
 */
public class Query implements Serializable {
    /**
     * The serial UID.
     */
    private static final long serialVersionUID = -4120293849787834585L;

    /**
     * @return the serialversionuid
     */
    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    /**
     * The pickup station.
     */
    private PUDStation pickup;
    /**
     * The delivery station.
     */
    private PUDStation delivery;
    /**
     * The quantity to deliver.
     */
    private int        quantity;
    /**
     * The max drive duration.
     */
    private int        maxDriveDuration;

    /**
     * Constructs a query from all the parameters.
     * @param pickup
     *            the pickup station
     * @param delivery
     *            the delivery station
     * @param maxDriveDuration
     *            the drive duration
     * @param aQuantity
     *            the quantity.
     */
    public Query(PUDStation pickup, PUDStation delivery, int maxDriveDuration,
            int aQuantity) {
        this.pickup = pickup;
        this.delivery = delivery;
        this.maxDriveDuration = maxDriveDuration;
        this.quantity = aQuantity;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object aObj) {
        if (aObj instanceof Query) {
            Query q = (Query) aObj;
            return this.getQuantity() == q.getQuantity()
                    && this.getDelivery().equals(q.getDelivery())
                    && this.getMaxDriveDuration() == q.getMaxDriveDuration()
                    && this.getPickup().equals(q.getPickup());
        }
        else {
            return false;
        }
    }

    /**
     * @return the delivery station
     */
    public PUDStation getDelivery() {
        return this.delivery;
    }

    /**
     * @return the maxDriveDuration
     */
    public int getMaxDriveDuration() {
        return this.maxDriveDuration;
    }

    /**
     * @return the pickup station
     */
    public PUDStation getPickup() {
        return this.pickup;
    }

    /**
     * @return the quantity
     */
    public int getQuantity() {
        return this.quantity;
    }

    /**
     * @param delivery
     *            the new delivery
     */
    public void setDelivery(PUDStation delivery) {
        this.delivery = delivery;
    }

    /**
     * @param i
     *            the new maxDriveDuration
     */
    public void setMaxDriveDuration(int i) {
        this.maxDriveDuration = i;
    }

    /**
     * @param pickup
     *            the new pickup
     */
    public void setPickup(PUDStation pickup) {
        this.pickup = pickup;
    }

    /**
     * @param i
     *            the new quantity
     */
    public void setQuantity(int i) {
        this.quantity = i;
    }

    public String toHTML() {
        String toReturn = "";
        toReturn += "<h3 style=\"color:green\">"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.PICK_UP_STATION)
                + " : </h3> zef"
                + this.getPickup().toHTML()
                + " <h3 style=\"color:red\">"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.DELIVERY_STATION)
                + " : </h3>"
                + this.getDelivery().toHTML()
                + "<h4 style=\"color:#FFA500\">"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.MAX_DRIVE_DURATION)
                + " : "
                + this.maxDriveDuration
                + "</h4>"
                + "<h4 style=\"color:#800080\">"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.STATION_QUANTITY_REQUIRED)
                + " : " + this.quantity + "</h4>";
        return toReturn;
    }

    @Override
    public String toString() {
        String toReturn = "";
        toReturn = LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.PICK_UP_STATION)
                + " : "
                + this.getPickup().toString()
                + "\n"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.DELIVERY_STATION)
                + " : "
                + this.getDelivery().toString()
                + "\n"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.MAX_DRIVE_DURATION)
                + " : "
                + this.maxDriveDuration
                + "\n"
                + LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.STATION_QUANTITY_REQUIRED)
                + " : " + this.quantity;
        return toReturn;
    }
}
